(use-modules (opencog logger))
(use-modules (opencog exec))

;; Well formed PutLink
(define put-1
(PutLink
  (LambdaLink
    (VariableNode "$X")
    (VariableNode "$X"))
  (ConceptNode "A"))
)

;; Ill formed PutLinks (only detectable at run-time)
(define put-2
(PutLink
  put-1
  (Concept "B"))
)
(define put-3
(PutLink
  put-2
  (Concept "C"))
)

(define get-put
(CollectionOf (Meet
  (TypedVariable
    (Variable "$P")
    (Type "PutLink"))
  (And
    (Variable "$P")
    (Evaluation
      (GroundedPredicate "scm: well-formed?")
      (Variable "$P")))))
)

(define (well-formed? P)
  (cog-logger-debug "well-formed? P = ~a" P)
  ; Execute the PutLink to check if it's well-formed
  ; Ill-formed PutLinks will throw an exception during execution
  (cog-execute! P)
  #t)
